*** ONLINE APPENDIX E: ADDRESSING GENERALIZABILITY WITH OLS ***
 
clear all
cap log close

global path ""
use "$path/OLS.dta", clear

// Table E1: Horizontal Dynasties and Spending (OLS) //
xtset idcode

* Column 1
reg log_pc_x_totexp num_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 2
xi: xtreg log_pc_x_totexp num_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 3
reg log_pc_x_totexp type_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 4
xi: xtreg log_pc_x_totexp type_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 5
reg log_pc_x_totexp n12_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 6
xi: xtreg log_pc_x_totexp n12_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 7
reg log_pc_x_totexp o12_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 8
xi: xtreg log_pc_x_totexp o12_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

// Table E2: Horizontal Dynasties and Night Lights (OLS) //
xtset idcode

* Column 1
reg log_DMSP_AVP_MEAN num_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 2
xi: xtreg log_DMSP_AVP_MEAN num_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 3
reg log_DMSP_AVP_MEAN type_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 4
xi: xtreg log_DMSP_AVP_MEAN type_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 5
reg log_DMSP_AVP_MEAN n12_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 6
xi: xtreg log_DMSP_AVP_MEAN n12_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 7
reg log_DMSP_AVP_MEAN o12_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 8
xi: xtreg log_DMSP_AVP_MEAN o12_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

// Table E3: Horizontal Dynasties and Poverty (OLS) //
xtset idcode

* Column 1
reg povincidence num_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 2
xi: xtreg povincidence num_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 3
reg povincidence type_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 4
xi: xtreg povincidence type_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 5
reg povincidence n12_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 6
xi: xtreg povincidence n12_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

* Column 7
reg povincidence o12_dynasty, robust cluster(idcode_prov)
estadd ysumm

* Column 8
xi: xtreg povincidence o12_dynasty i.year, fe robust cluster(idcode_prov)
estadd ysumm

// Figure E1: //
cap program drop specchart
program specchart
syntax varlist, [replace] spec(string)
	* save current data
	tempfile temp
	save "`temp'",replace
	*dataset to store estimates
	if "`replace'"!=""{
			clear
			gen beta=.
			gen se=.
			gen spec_id=.
			gen u95=.
			gen u90=.
			gen l95=.
			gen l90=.
			save "estimates.dta",replace
	}	
	else{
		* load dataset
		use "estimates.dta",clear
	}
	* add observation
	local obs=_N+1
	set obs `obs'
	replace spec_id=`obs' if _n==`obs'
	* store estimates
	replace beta =_b[`varlist'] if  spec_id==`obs'
	replace se=_se[`varlist']   if  spec_id==`obs'
	replace u95=beta+invt(e(df_r),0.975)*se if  spec_id==`obs'
	replace u90=beta+invt(e(df_r),0.95)*se if  spec_id==`obs'
	replace l95=beta-invt(e(df_r),0.975)*se  if  spec_id==`obs'
	replace l90=beta-invt(e(df_r),0.95)*se  if  spec_id==`obs'
	* store specification
	foreach s in `spec'{
		cap gen `s'=1 			if  spec_id==`obs'
		cap replace `s'=1 		 if  spec_id==`obs'
	}
		save "estimates.dta",replace
	* restore dataset
	use `temp',clear
end

capture reg log_pc_x_totexp num_dynasty   
specchart  num_dynasty,spec(FE_no) replace

local CON_1 "experience"
local CON_2 "sex"
local CON_3 "dynasty_past"
local CON_4 "same_party_h1"
local CON_5 "num_cand"
local CON_6 "pct_urban"

foreach y in totexp {
foreach x in num type n12 o12 {

xtset idcode

foreach c of num 1/6 {
capture reg log_pc_x_`y' `x'_dynasty `CON_`c'', robust cluster(idcode_prov)
specchart  `x'_dynasty,spec(DYN_`x' CON_`c') 

capture reg log_pc_x_`y' `x'_dynasty `CON_`c'' i.year, robust cluster(idcode_prov)
specchart  `x'_dynasty,spec(DYN_`x' CON_`c' FE_year) 

capture xi: xtreg log_pc_x_`y' `x'_dynasty `CON_`c'', fe robust cluster(idcode_prov)
specchart  `x'_dynasty,spec(DYN_`x' CON_`c' FE_mun) 

capture xi: xtreg log_pc_x_`y' `x'_dynasty `CON_`c'' i.year, fe robust cluster(idcode_prov)
specchart  `x'_dynasty,spec(DYN_`x' CON_`c' FE_year FE_mun)

}
}
}

use "estimates.dta", clear
drop if _n == 1
replace spec_id = spec_id - 1

duplicates drop DYN_num DYN_type DYN_n12 DYN_o12 CON_1 CON_2 CON_3 CON_4 CON_5 CON_6 FE_year FE_mun, force

drop if (FE_mun == 1 & FE_year == .) | (FE_mun == . & FE_year == 1)
drop if CON_1 == 1 & CON_2 == 1 & CON_3 == 1 & CON_4 == 1 & CON_5 == 1 & CON_6 == 1

gsort -DYN_o12 -DYN_n12 -DYN_type -DYN_num ///
		-FE_mun -FE_year ///
		-CON_6 -CON_5 -CON_4 -CON_3 -CON_2 -CON_1, mfirst

gen rank=_n

	local scoff=" "
	local scon=" "
	local ind=-0.31

	foreach var in DYN_num DYN_type DYN_n12 DYN_o12 CON_1 CON_2 CON_3 CON_4 CON_5 CON_6 FE_year FE_mun {
	   cap gen i_`var'=`ind'
	   local ind=`ind'-0.05
	   
	   local scoff="`scoff' (scatter i_`var' rank,msize(vsmall) mcolor(gs10))" 
	   local scon="`scon' (scatter i_`var' rank if `var'==1,msize(vsmall) mcolor(black))"
	   
	   if "`var'" == "DYN_o12" | "`var'" == "CON_6" {
	   local ind=`ind'-0.1
	   }
	}

gen zero = 0

tw (rbar u95 l95 rank, fcolor(gs12) lcolor(gs12) lwidth(none)) /// 95% CI
   (rbar u90 l90 rank, fcolor(gs6) lcolor(gs16) lwidth(none)) /// 90% CI
   (scatter beta rank, mcolor(black) msymbol(d) msize(*0.2)) ///  point estimates
   (line zero rank, lcolor(red) lpattern(shortdash)) /// zero line
   `scoff' `scon' /// indicators for spec
   , legend(order(3 "Point Estimate" 1 "95% CI" 2 "90% CI") region(lcolor(white)) ///
	pos(6) ring(1) rows(1) size(vsmall) symysize(small) symxsize(small)) ///
   xtitle(" ") ytitle(" ") title("Dependent Variable: Spending", size(medsmall)) ///
   yscale(noline) xscale(noline) ylab(-0.1(0.1)0.3,noticks nogrid angle(horizontal) labsize(vsmall)) xlab("", noticks)  ///
   graphregion (fcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(white))
   
gr_edit .yaxis1.add_ticks -0.25 `"Independent Variable"', custom tickset(major) editstyle(tickstyle(textstyle(size(small))) )
gr_edit .yaxis1.add_ticks -0.3 `"HD (Linear)"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.35 `"HD (1 vs. >1)"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.4 `"HD (1 vs. 2)"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.45 `"HD (1 vs. 2, limit)"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )

gr_edit .yaxis1.add_ticks -0.55 `"Control Variable"', custom tickset(major) editstyle(tickstyle(textstyle(size(small))) )
gr_edit .yaxis1.add_ticks -0.6 `"Tenure"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.65 `"Gender"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.7 `"Dynastic Past"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.75 `"Party Affiliation"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.8 `"No. of Candidates"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -0.85 `"Urban"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )

gr_edit .yaxis1.add_ticks -0.95 `"Fixed Effects"', custom tickset(major) editstyle(tickstyle(textstyle(size(small))) )
gr_edit .yaxis1.add_ticks -1.0 `"Year"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )
gr_edit .yaxis1.add_ticks -1.05 `"Municipality"', custom tickset(major) editstyle(tickstyle(textstyle(size(vsmall))) )

gr_edit .yaxis1.add_ticks 0.4 `"Coefficient"', custom tickset(major) editstyle(tickstyle(textstyle(size(small))) )
